﻿#pragma once

struct _stTerrainIDInfo;
struct _stTerrainTypeInfo;
struct _stLandedTitlesData;
struct _stStrategyBorderVerticesInfo;
struct _stProvincePosition;

struct _stProvinceInfo
{
public:
	WORD nProvinceID = 0;		// Key
	std::wstring IndexName = L"";
	std::wstring DisplayName = L"";

	std::wstring GetDisplayName() const;

private:
	bool bSelect = false;
public:
	bool IsSelect() const { return bSelect; }
	void SetSelect(bool bSelect) { this->bSelect = bSelect;	}

	std::set<_stProvinceInfo*> setAdjoinProvince;		// 临接省份
	std::set<_stStrategyBorderVerticesInfo*> setProvinceBorder;		// 省份边界的mesh指针
	
	std::set<int> setAreaIn;			// 省份所在的渲染区域 拿到setProvinceBorder之后 再赋值
	void InitAreaIn();

	_stLandedTitlesData* pLandedTitlesData = nullptr;
	const _stProvincePosition* pProvincePosition = nullptr;
public:
	// 地形
	const _stTerrainIDInfo* pst_TerrainPriority = nullptr;	// 若pst_TerrainPriority为NULL pst_TerrainInfo就有意义了
	const _stTerrainTypeInfo* pst_TerrainInfo = nullptr;

	const _stTerrainTypeInfo* GetTerrainInfo() const;	// 用这个来取地形数据

	bool IsAvailable() const { return nProvinceID != 0; }
	bool IsCountyPalatine() const { return nullptr != pLandedTitlesData; }		// 是否是伯爵领
};

class CProvinceData
{
	friend class CProgramDataMgr;	// 只有CProgramDataMgr能实例化

public:
	// 实体数据
	std::unordered_map<WORD, _stProvinceInfo> m_mapProvinceInfo; // Key 省份ID Value 省份信息

public:
	void InseradjacentProvince(_stProvinceInfo* key, _stProvinceInfo* value);	// 操作m_mapAdjoinProvince

private:
	std::unique_ptr<_stProvinceInfo*> m_pEachPointProvinceInfo = nullptr;	// 每个点的省份指针 有些地点会为NULL

public:
	const _stProvinceInfo* const* GetEachPointProvincePointer() const { return m_pEachPointProvinceInfo.get(); }		// 有些地点会为NULL

public:
	void InitAreaIn();		// 初始化 省份所在的渲染区域 拿到setProvinceBorder之后 再赋值

public:
	~CProvinceData() = default;
private:
	CProvinceData() = default;
	CProvinceData(const CProvinceData&) = delete;
	CProvinceData& operator =(const CProvinceData&) = delete;

	bool IsDataComplete() const;
	bool CreateProvinceData(const BYTE* pTerrainID, _stRGB*& pProvinceRGB);
	bool TidyProvinceTerrain();		// 将沿海的沙漠置换为沿海沙漠 将原本的沿海沙漠置换为海洋
	void LinkLandedTitleNProvinceData();		// 链接ProvinceData和LandedTitle
	void LinkPositions2ProvinceData();		// 链接ProvinceData和ProvincePositions
};